Repository navigation
Conversation
Closes pybind#4108. Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
|
— codex on behalf of Ralf — Preserve the documented custom |
A custom variant can accept an alternative by assignment only, with no converting constructor. Use emplace(alternative) only if the variant is not default constructible. Assisted-by: ClaudeCode:claude-fable-5-2
|
— codex on behalf of Ralf — The assignment-only custom variant now works again. I reran the original C++17 repro and checked value and reference loading for the supported non-default-first Gate the non-default variant tests on standard variant support. The new fixtures are enabled whenever Generated by Codex. Ralf has yet to review these findings. |
Older Boost reports boost::variant as default constructible when it is not. Assisted-by: ClaudeCode:claude-fable-5-2
|
🤖 AI text below 🤖 Done in 5db0d80. The non-default variant fixtures now require |
🤖 AI text below 🤖
Description
Closes #4108.
variant_casterusedPYBIND11_TYPE_CASTER, which declares aType valuemember. If the first alternative of the variant is not default constructible, any function that takes the variant failed to compile.With C++17 (
PYBIND11_HAS_OPTIONAL), the caster now stores the value instd::optional<Type>and writes out the parts ofPYBIND11_TYPE_CASTERit needs. Without C++17 (boost::variantin C++11/14), the code is not changed.An alternative is a new macro in
cast.hthat takes the storage type. That is cleaner but a larger change.Suggested changelog entry:
std::variantarguments now work when the first alternative is not default constructible.